package com.xuhuan.demo.filerepeat.demo;

import com.alibaba.fastjson.JSONObject;
import com.xuhuan.demo.filerepeat.util.FileRepeatUtil;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.util.Map;
import java.util.Set;

/**
 * @Author huan.xu
 * @Date 2023/7/8 14:54
 * @Description 文件重复工具类案例
 */
@Slf4j
public class FileRepeatUtilDemo {

    /**
     * 查找内容重复的文件
     */
    @Test
    public void getDirRepeatContentFile() throws Exception {
        String dirPath = "E:\\9.幼儿教育\\百度云资料";
        String[] ignoreChildDirPath = {
                "E:\\9.幼儿教育\\百度云资料\\【1】小学英语语法练习344页等",
                "E:\\9.幼儿教育\\百度云资料\\【16】美国家庭万能亲子英语8000句",
                "E:\\9.幼儿教育\\百度云资料\\penelope蓝色小考拉"
        };
        Map<String, Set<String>> dirRepeatFile = FileRepeatUtil.getDirRepeatContentFile(dirPath, ignoreChildDirPath);
        Set<Map.Entry<String, Set<String>>> entries = dirRepeatFile.entrySet();
        entries.stream()
                .forEach(entry -> {
                    log.info("---------------{}------------------", entry.getKey());
                    Set<String> entryValue = entry.getValue();
                    entryValue.stream().forEach(p -> {
                        log.info(p);
                    });
                    log.info("---------------{}------------------", entry.getKey());
                });
//        log.info(JSONObject.toJSONString(dirRepeatFile));

    }

    /**
     * 查找全部文件
     */
    @Test
    public void getDirFile() throws Exception {
        String dirPath = "C:\\Users\\Administrator\\Desktop\\file-repeat";
        Map<String, Object> dirNotRepeatFile = FileRepeatUtil.getDirFile(dirPath);
        log.info(JSONObject.toJSONString(dirNotRepeatFile));
    }

    /**
     * 查找名称重复的文件
     */
    @Test
    public void getDirRepeatNameFile() throws Exception {
        String dirPath = "C:\\Users\\Administrator\\Desktop\\file-repeat";
        Map<String, Set<String>> dirNotRepeatFile = FileRepeatUtil.getDirRepeatNameFile(dirPath);
        log.info(JSONObject.toJSONString(dirNotRepeatFile));
    }
}
